package com.powernode.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.powernode.domain.ProdComm;
import com.powernode.service.ProdCommService;
import com.powernode.vo.ProdCommOverview;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 内容:
 * 作者: cy
 */
@RestController
@RequestMapping("prod/prodComm")
@Api(tags = "评论管理接口")
public class ProdCommController {

    @Autowired
    private ProdCommService prodCommService;


    @GetMapping("page")
    @ApiOperation("分页查询评论列表")
    @PreAuthorize("hasAuthority('prod:prodComm:page')")
    public ResponseEntity<Page<ProdComm>> loadProdCommPage(Page<ProdComm> page, ProdComm prodComm) {
        Page<ProdComm> prodCommPage = prodCommService.selectProdCommPage(page, prodComm);
        return ResponseEntity.ok(prodCommPage);
    }


    @GetMapping("prodComm/prodCommData")
    @ApiOperation("根据商品id查询评论总览")
    public ResponseEntity<ProdCommOverview> loadFrontProdCommOverview(Long prodId) {
        ProdCommOverview prodCommOverview = prodCommService.selectFrontProdCommOverview(prodId);
        return ResponseEntity.ok(prodCommOverview);
    }


    @GetMapping("prodComm/prodCommPageByProd")
    @ApiOperation("根据商品id分页查询评论信息")
    public ResponseEntity<Page<ProdComm>> loadFrontProdCommPageByProdId(Page<ProdComm> page ,Long prodId) {
        Page<ProdComm> prodCommPage = prodCommService.selectFrontProdCommPageByProdId(page,prodId);
        return ResponseEntity.ok(prodCommPage);
    }


}
